/**
 * 初始信息量图标
 */
define(function(){
    var ec=require('echarts');
    require('echarts/chart/line');
    require('echarts/chart/bar');
    var zrnumber = require('echarts/util/number');

    var myChart1 = ec.init(document.getElementById('info_line1')); 
    var myChart2 = ec.init(document.getElementById('info_line2'));

    var option_1 = {

        tooltip : {
            trigger: 'axis',
            formatter: tooltipFunc_1
        },
        legend: {
            data:[]
        },
        toolbox: {
            show : true,
            showTitle: true,
            orient:'vertical',
            feature : {
                mark : {show: false},
                dataZoom : {show: true},
                magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        calculable : true,
        grid: {
            y: 60,
            y2:15
        },
        dataZoom: {
            height: 20,
            y:250,
            realtime : true
        },        
        xAxis: [{
            type: "category",
            position:'top',
            boundaryGap: true,
            data:[''],
            axisLabel:{formatter:function(value){
                return value;
            }}
        }],
        yAxis: [
            {
                type: 'value'
            }
        ],

        series: [
            {
                name: '',
                type: 'line',
                data:[]
            }
        ]
    };

   var option_2 = {

        tooltip : {
            trigger: 'axis',
            formatter: tooltipFunc_2
        },
        legend: {    
            y: 'bottom',
            data:[]
        },
        toolbox: {
            show : false,
            showTitle: true,
            orient:'vertical',
            feature : {
                mark : {show: false},
                dataZoom : {show: true},
                magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        calculable : true,
        grid: {          
            y: 35,
            y2:60
        },        
        dataZoom: {
            show: true,
            y: 0,
            height: 20,
            realtime : true,
            start: 90
        },        
        xAxis: [{
            type: "category",
            boundaryGap: true,
            data:[''],
            axisLabel:{formatter:function(value){
                return value;
            }}
        }],
        yAxis: [
            {
                type: 'value'
            }
        ],

        series: [
            {
                name: '',
                type: 'line',
                data:[]
            }
        ]
    };

   
   var nameMap_1 = {"个人":"person_rs","免费商家":"freesj_rs","VIP":"vip_rs","all":"all_rs"};
   var nameMap_2 = {"个人":"person_info","免费商家":"freesj_info","VIP":"vip_info","all":"all_info"};
// 图例一一对应
   var legendMap  = {"个人有效信息人数":'个人有效信息量','免费商家有效信息人数':"免费商家有效信息量",'VIP有效信息人数':'VIP有效信息量','all有效信息人数':'all有效信息量'};

    /**
     * 根据指标显示日数据
     * @param eventType= 2:第一次加载, 1:切换日，周，月刷新 , 0: 添加对比后又重新选择指标
     */
    function show(eventType){
    	var statType = $('#infoOption').attr('statType');
        var proType = $('#proType').val();
        var cityName = $('#cityName').val();
        var cateName = $('#cateName').val();
        var businessName = $('#businessName').val();
        myChart1.showLoading({ text: '正在努力的读取数据中...' });
        myChart2.showLoading({ text: '正在努力的读取数据中...' });
        $.ajax({
        	url: '/dashboard/homePage/ajax/info',
            type: 'post',
            async: true,
            data:{"businessName": businessName, "cityName":cityName, "cateName":cateName,"proType":proType,"statType":statType,"dataType":"chart"},              dataType: 'json',
            success: function(data, textStatus) {
                //X轴时间
                option_1.xAxis[0].data = data.time;
                option_2.xAxis[0].data = data.time;
                //legend
                //option_1.legend.data = data.legend;
                //option_2.legend.data = data.legend;
                //option_2.legend.show = false;
                //上图每条曲线
                var i = 0;
                var j = 0;
                var series_local = [];
                var legend_local = [];
                var legend = '';
                $.each(data.legend,function(index,value){
                	    legend = value+'有效信息人数';
                	    legend_local[j++] = legend ;
                    	series_local[i++] = {
                    			name: legend,
                    			type: 'line',
                    			smooth: true,
                    			symbol:"none",
                    			'data': data[nameMap_1[value]]
                    	};                    
                });
                option_1.series = series_local;
                option_1.legend.data = legend_local;
                //下图每条曲线
                i = 0;
                j = 0;
                series_local = [];
                legend_local = [];
                $.each(data.legend,function(index,value){
                	legend = value+'有效信息量';
                	legend_local[j++] = legend;
                	series_local[i++] = {
                			name: legend,
                			type: 'line',
                			smooth: true,
                			symbol:"none",
                			'data': data[nameMap_2[value]]
                	};  
                });
                option_2.series = series_local;
                option_2.legend.data = legend_local;
                //区域缩放
                var datezoom_local={
                    day:{start:(1-31/data.time.length)*100,end:100},
                    week:{start:(1-12/data.time.length)*100,end:100},
                    month:{start:0,end:100},
                };
                //少于31个点，全显
                if(data.time.length<31){
                    datezoom_local={
                        day:{start:0,end:100},
                        week:{start:0,end:100},
                        month:{start:0,end:100},
                    };
                }

                if(eventType == 1 || eventType == 2){
                    if('month' == statType){
                        option_1.xAxis[0].axisLabel.formatter=function(value){ return value.substr(0,4)+"年"+value.substr(4,2)+"月"; } ;
                        option_2.xAxis[0].axisLabel.formatter=function(value){ return value.substr(0,4)+"年"+value.substr(4,2)+"月"; } ;
                    }else{
                        option_1.xAxis[0].axisLabel.formatter=function(value){ return value; } ;
                        option_2.xAxis[0].axisLabel.formatter=function(value){ return value; } ;
                    }
                    option_1.dataZoom.start=datezoom_local[statType].start;
                    option_1.dataZoom.end=datezoom_local[statType].end;
                    option_2.dataZoom.start=datezoom_local[statType].start;
                    option_2.dataZoom.end=datezoom_local[statType].end;
                    if(eventType == 1 && myChart2.component.dataZoom){
                        myChart1.component.dataZoom.absoluteZoom(datezoom_local[statType]);
                        myChart2.component.dataZoom.absoluteZoom(datezoom_local[statType]);
                        option_2.dataZoom.show=true;
                    }else if(eventType == 2){
                        option_2.dataZoom.show=!$('#time_checkbox_info').is(":checked"); //false;
                    }
                    myChart1.setOption(option_1,true);
                    myChart2.setOption(option_2,true);
                }else if(eventType == 0){
                    setDataZoom(xAxis_show[0], xAxis_show[xAxis_show.length-1]);
                    myChart1.setOption(option_1,true);
                    myChart2.setOption(option_2,true);
                    if($('#time_input_info').val()){
                        EC.addCompare_1($('#time_input_info').val());
                        EC.addCompare_2($('#time_input_info').val());
                    }
                }
                // myChart.clear();
                myChart1.connect(myChart2);
                myChart2.connect(myChart1);
                myChart1.hideLoading();
                myChart2.hideLoading();
            },
            error : function() {
                myChart1.hideLoading();
                myChart2.hideLoading();
            }
        });
    }

  
    var ecConfig = require('echarts/config');
    //鼠标click事件
    function eventClick(param){
        var click_date = '2014-01-01';
        if (typeof param.seriesIndex != 'undefined') {
            click_date = param.name;
        }
        loadTableData(click_date);
    }
    myChart1.on(ecConfig.EVENT.CLICK, eventClick);
    myChart2.on(ecConfig.EVENT.CLICK, eventClick);
    //加载27个直销城市当天的数据，, 0:字符, 1:数字, 2:百分比
  // var show_cols = {"cate_name":0,"jzcash":1,"jzash_chain":2,"jzcost_user":1,"jzcost_user_chain":2,"zdcash":1,"zdcash_chain":2,"zdcost_user":1,"zdcost_user_chain":2};
    //新增类型
    var show_cols1 = {"user_type_name":0,"info_valid_add_count":1,"ivac_chain":2,"user_valid_add_count":1,"uvac_chain":2};
    //修改类型
    var show_cols2 = {"user_type_name":0,"info_valid_update_count":1,"ivuc_chain":2,"user_valid_update_count":1,"uvuc_chain":2};
    //设置刷新类型
    var show_cols3 = {"user_type_name":0,"info_setup_rep_count":1,"isrt_chain":2,"user_setup_rep_count":1,"usrc_chain":2}; 
    var show_cols = {};
    function loadTableData(stat_date){
    	var statType = $('#infoOption').attr('statType');
        var proType = $('#proType').val();
        var cityName = $('#cityName').val();
        var cateName = $('#cateName').val();
        var businessName = $('#businessName').val();
        $.ajax({
            url: '/dashboard/homePage/ajax/info',
            type: 'post',
            async: true,
            data:{"businessName": businessName, "cityName":cityName, "cateName":cateName,"proType":proType,"statType":statType,"dataType":"table","dateVal":stat_date},
            dataType: 'json',
            success: function(data, textStatus) {

                var resultList = data.dataList;
                var htmlRows = "";
                if(proType == 'valid_add'){
                	show_cols = show_cols1;
                }else if(proType == 'valid_update'){
                	show_cols = show_cols2;
                }else{
                	show_cols = show_cols3;
                }
                $.each(resultList,function(i,vo){
                    htmlRows += "<tr align='center'>";

                    $.each(show_cols,function(col,colType){
                        switch(colType){
                            case 0:
                                htmlRows += "<td>";
                                htmlRows += vo[col];
                                htmlRows += "</td>";
                                break;
                            case 1:
                                htmlRows += "<td>";
                                htmlRows += zrnumber.addCommas(vo[col]);
                                htmlRows += "</td>";
                                break;
                            case 2:
                                htmlRows += getRate(vo[col]);
                                break;
                            case 3:
                                htmlRows += "<td>";
                                htmlRows += parseFloat(vo[col]).toFixed(2)+"%";
                                htmlRows += "</td>";
                                break;                                   
                        }
                    });

                    htmlRows += "</tr>";
                });

                $('#infoTotalTable tr:gt(0)').remove();
                $('#infoTotalTable_date').text(stat_date.replace(/\-/g,"."));
                $('#infoTotalTable').append(htmlRows);
            },
            error : function() {

            }
        }); 
    }
   
    

    var ecConfig = require('echarts/config');
 
    var all_Options = [option_1,option_2];
    function tooltipFunc_1(params, ticket, callback){
        return tooltipFunc(params, ticket, callback,all_Options[0],"");
    }
    function tooltipFunc_2(params, ticket, callback){
        return tooltipFunc(params, ticket, callback,all_Options[1],"");
    } 
    
  //提示框
    function  tooltipFunc(params, ticket, callback,option_line,prex){
        var dateVal = formatShowDate(params[0].name);
        var curOption = option_line;
        var index_current=getIndexByName(curOption.xAxis[0].data,params[0].name);

        var result='<table class="table-center">';
        result+='<tr><td>'+dateVal+'</td><td>';
        var isStatDay = isDay(); 
        if(isStatDay)
            result += getWeekDay(dateVal);
        result += '</td>';
        if(isStatDay)
            result +="<td>日环比</td><td>周同比</td>";
        else if(isWeek())
            result += "<td>周环比</td>";
         else if(isMonth())
            result += "<td>月环比</td><td>月同比</td>";
        result += '</tr>';


        $(params).each(function(index,para){
            result+='<tr><td>'+para.seriesName+prex+'</td><td>'+zrnumber.addCommas(para.data)+'</td>';
            var seriesIndex = para.seriesIndex;
            var day_td="<td>--</td>";
            //日周月 环比(前一日周月)
            if(index_current-1>=0){
                var data_yesday = null;
                data_yesday= curOption.series[seriesIndex].data[index_current-1];                
                if(data_yesday != null){
                    var s=(((para.data/data_yesday)-1)*100).toFixed(2);
                    if(data_yesday == 0 ){
                  	  if(para.data>data_yesday){
                  		  day_td='<td style="color: orangered;">100%&#8593</td>';
                  	  }
                  	  else if(para.data<data_yesday){
                  		  day_td='<td style="color: greenyellow;">-100%&#8595</td>';
                  	  } else{
                  		  day_td='<td style="color: greenyellow;">0%</td>';
                  	  } 
                    }else {
                    
	                      if(s>0){
	                          day_td='<td style="color: orangered;">'+s+'%&#8593</td>';
	                      }else{
	                          day_td='<td style="color: greenyellow;">'+s+'%&#8595</td>';
	                      }
                    }
                }
            }
            result += day_td;
            //周同比(日)
             if(isStatDay){
                 var week_td='<td>--</td>';
                 if(index_current-7>=0){
                     data_week= curOption.series[seriesIndex].data[index_current-7];
                     var s=(((para.data/data_week)-1)*100).toFixed(2);
                     if(data_week == 0 ){
                   	  if(para.data>data_week){
                   		 week_td='<td style="color: orangered;">100%&#8593</td>';
                   	  }
                   	  else if(para.data<data_week){
                   		 week_td='<td style="color: greenyellow;">-100%&#8595</td>';
                   	  } else{
                   		 week_td='<td style="color: greenyellow;">0%</td>';
                   	  } 
                     }else {
                     
	                      if(s>0){
	                    	 week_td='<td style="color: orangered;">'+s+'%&#8593</td>';
	                      }else{
	                    	 week_td='<td style="color: greenyellow;">'+s+'%&#8595</td>';
	                      }
                     }
                 }
                 result += week_td;
             }
            //去年同月
            if(isMonth()){
                var td='<td>--</td>';
                var data_last = null;
                if(index_current-12>=0){
                   data_last= option_day.series[seriesIndex].data[index_current-12];
               }
                if(data_last != null){
                   var s=(((para.data/data_last)-1)*100).toFixed(2);
                   if(data_last == 0 ){
                  	  if(para.data>data_last){
                  		 td='<td style="color: orangered;">100%&#8593</td>';
                  	  }
                  	  else if(para.data<data_last){
                  		 td='<td style="color: greenyellow;">-100%&#8595</td>';
                  	  } else{
                  		 td='<td style="color: greenyellow;">0%</td>';
                  	  } 
                    }else {
                    
	                      if(s>0){
	                    	 td='<td style="color: orangered;">'+s+'%&#8593</td>';
	                      }else{
	                    	 td='<td style="color: greenyellow;">'+s+'%&#8595</td>';
	                      }
                    }
               }
               result += td;
           }                   
              result += '</tr>';
        });
        result+='</table>';
        return result;
    }        
  
   function formatShowDate(yyyymmdd){
        var statType = $('#infoOption').attr('statType');
        if('month'==statType){
            return yyyymmdd.substr(0,4)+"年"+yyyymmdd.substr(4,2)+"月";
        }else{
             return yyyymmdd;
        }
    }

    function isDay(){
        var statType = $('#infoOption').attr('statType');
        if('day'==statType){
            return true;
        }
        return false;
    }

        function isWeek(){
         var statType = $('#infoOption').attr('statType');
        if('week'==statType){
            return true;
        }
        return false;
    }

    function isMonth(){
        var statType = $('#infoOption').attr('statType');
        if('month'==statType){
            return true;
        }
        return false;
    }

    var zrUtil = require('zrender/tool/util');
    // console.log(zrUtil);

    var xAxis_show;     // X轴所显示的时间区间
    var legend_SelectedMap={};  //需要记忆图例的选择状态
    function hideDataZoom(){
        var legend_SelectedMap_1=zrUtil.clone(myChart1.component.legend.getSelectedMap());
        var legend_SelectedMap_2=zrUtil.clone(myChart2.component.legend.getSelectedMap());
        legend_SelectedMap = zrUtil.merge(legend_SelectedMap_1, legend_SelectedMap_2, true);
        xAxis_show=zrUtil.clone(myChart1.component.dataZoom.option.xAxis[0].data);    //记忆缩放
        option_2.dataZoom.show=false;

        myChart1.setOption(option_1,false);
        myChart2.setOption(option_2,false);
    }
    var temp = false;
    //添加对比--图一
    function addCompare_1(time){
        time=formatTime(time);
        var copy=zrUtil.clone(option_1);
        copy.toolbox.feature.magicType.show=false;
        copy.toolbox.feature.dataZoom.show=false;
        var index_time=getIndexByName(option_1.xAxis[0].data,time);
   
        if(index_time == -1){
        	alert("当天没有数据，无法进行对比！");
        	temp = true;
        	return ;
        }
        var index_show=getIndexByName(option_1.xAxis[0].data,getShowDays()[0]);
        var length=getShowDays().length;
        setCompareXaxis(option_1,copy,index_time,index_show,length);
        var index=0;
        //选中对比时，再次选择指标，需要记忆图例的选择状态
        $.each(legend_SelectedMap,function(key,value){
            //判断是否在当前图例值中，应为echarts会把"对比时间段"也放入SelectedMap
            if($.inArray(key,option_1.legend.data) != -1){
                if(value){
                    return false;
                }
                index++;
            }     
        });
        // console.log(index);
        if(index<4){
            setCompareSeries(option_1,copy,index,index_time,index_show,length);
            setCompareLegend(copy);
            setCompareTooltip(copy);
            delete copy.dataZoom;
            copy.xAxis[1].axisLabel.show = false;
            myChart1.restore();
            myChart1.setOption(copy,true);
        }

    }

    //添加对比--图二
    function addCompare_2(time){
        time=formatTime(time);
        var copy=zrUtil.clone(option_2);
        copy.toolbox.feature.magicType.show=false;
        copy.toolbox.feature.dataZoom.show=false;
        var index_time=getIndexByName(option_2.xAxis[0].data,time);
        if(temp){
        	temp = false;
        	return ;
        }
        var index_show=getIndexByName(option_2.xAxis[0].data,getShowDays()[0]);
        var length=getShowDays().length;
        setCompareXaxis(option_2, copy,index_time,index_show,length);
        var index=0;
        //选中对比时，再次选择指标，需要记忆图例的选择状态
        $.each(legend_SelectedMap,function(key,value){
            //判断是否在当前图例值中，应为echarts会把"对比时间段"也放入SelectedMap
            if($.inArray(key,option_2.legend.data) != -1){
                if(value){
                    return false;
                }
                index++;
            }     
        });
        // console.log(index);
        if(index<4){
            setCompareSeries(option_2, copy,index,index_time,index_show,length);
            setCompareLegend(copy);
            setCompareTooltip(copy);
            delete copy.dataZoom;
            copy.xAxis[1].axisLabel.margin = 16;
            myChart2.restore();           
            myChart2.setOption(copy,true);
        }

    }

   

    //设置缩放区间
    function setDataZoom (startDate,endDate) {
        var xAxisLength = option_2.xAxis[0].data.length;
        var index_start=getIndexByName(option_2.xAxis[0].data,startDate) + 1;
        var index_end=getIndexByName(option_2.xAxis[0].data,endDate) + 1;
        var zoomRange = {start:((index_start-1)/xAxisLength)*100,end:index_end/xAxisLength*100};
        myChart2.component.dataZoom.absoluteZoom(zoomRange);
    }

    //取消对比
    function removeCompare(){
        //恢复缩放

        option_2.dataZoom.show=true;
        //恢复图例的选择状态
        $.each(legend_SelectedMap,function(key,value){
            if($.inArray(key,option_1.legend.data) != -1){
                myChart1.component.legend.setSelected(key,value);
            }else if($.inArray(key,option_2.legend.data) != -1){
                myChart2.component.legend.setSelected(key,value);
            }else{
                myChart1.component.legend.setSelected(key,false);
                myChart2.component.legend.setSelected(key,false);
            }
        });

        setDataZoom(xAxis_show[0], xAxis_show[xAxis_show.length-1]);
        myChart1.setOption(option_1,true);
        myChart2.setOption(option_2,true);
    }


    function setCompareTooltip(copy){
        copy.series[1]&&copy.series[1].tooltip&&(copy.series[1].tooltip={show:false});
        copy.series[2]&&copy.series[2].tooltip&&(copy.series[2].tooltip={show:false});
        copy.series[3]&&copy.series[3].tooltip&&(copy.series[3].tooltip={show:false});

        copy.tooltip.formatter=function(params, ticket, callback){
        	
            var date_current=params[0][1];
            var data_current=params[0][2];
            var index_current=getIndexByName(copy.xAxis[0].data,date_current);

            var dateVal = formatShowDate(date_current);
            var result='<table class="table-center">' +
                '<tr><td>'+dateVal;
            //是日要显示周几
            if(isDay())
                 result += ' ('+getWeekDay(dateVal)+')';
            result += '</td><td>'+zrnumber.addCommas(data_current)+'</td></tr>';
            if(copy.series[1]){
                var data_compare=copy.series[1].data[index_current];
                var s=(((data_current-data_compare)/data_compare)*100).toFixed(2);
                dateVal = formatShowDate(copy.xAxis[1].data[index_current]);
                result+='<tr><td>'+dateVal;
                if(isDay())
                    result += ' ('+getWeekDay(dateVal)+')';
                result += '</td><td>'+zrnumber.addCommas(data_compare)+'</td></tr>';
	            if(data_compare == 0){
	            	 if(data_current>data_compare){
	            		 result+='<tr><td>变化</td><td style="color: orangered">100%&#8593</td></tr>';
	            	 }else if(data_current<data_compare){
	            		 result+='<tr><td>变化</td><td style="color: greenyellow">100%&#8595</td></tr>';
	            	 }else{
	            		 result+='<tr><td>变化</td><td style="color: greenyellow">0%</td></tr>';
	            	 }
	            }else{
	            	if(s>0){
	            		result+='<tr><td>变化</td><td style="color: orangered">'+s+'%&#8593</td></tr>';
	            	}else{
	            		result+='<tr><td>变化</td><td style="color: greenyellow">'+s+'%&#8595</td></tr>';	            	         	
	                }
	            }
            }
            result+='</table>';
            return   result;
        }
    }

    function setCompareLegend(copy){
        copy.legend.data=[copy.series[0].name, copy.series[1].name];
        copy.legend.selectedMode=false;
    }

    function  setCompareSeries(option_day,copy,index,index_time,index_show,length){
        copy.series=[];
        //原来数据
        copy.series.push(zrUtil.clone(option_day.series[index]));
        copy.series[0].type='line';
        copy.series[0].data=option_day.series[index].data.slice(index_show,index_show+length);
        delete  copy.series[0].stack;
        delete  copy.series[0].itemStyle;
        //对比数据
        copy.series.push(zrUtil.clone(option_day.series[index]));
        copy.series[1].type='line';
        copy.series[1].name="对比时间段";
        copy.series[1].xAxisIndex=1;
        delete  copy.series[1].stack;
        delete  copy.series[1].itemStyle;

        copy.series[1].data=option_day.series[index].data.slice(index_time,index_time+length);
        if(length>32){return}
        //对比柱
        copy.series.push({
            tooltip:{show:false},
            show:false,
            name: '对比时间段1',
            type: 'bar',
            stack: '1',
            barWidth:3,
            xAxisIndex:1,
            itemStyle:{
                normal:{
                    color:'rgba(0,0,0,0)'
                },
                emphasis:{
                    color:'rgba(0,0,0,0)'
                }
            },
            data: function(){
                var i=0;
                return $.map(copy.series[1].data,function(val){
                    var tt=copy.series[0].data[i++];
                    if(toNum(val)<toNum(tt)){
                        return val;
                    }else{
                        return tt;
                    }
                })
            }()
        });
        copy.series.push({
            tooltip:{show:false},
            name: '变化',
            type: 'bar',
            stack: '1',
            xAxisIndex:1,
            data: function(){
                var i=0;
                return $.map(copy.series[1].data,function(val){
                    var tt=copy.series[0].data[i++];
                    if(toNum(val)<toNum(tt)){
                        return tt-val;
                    }else{
                        return {value : val-tt, itemStyle:{ normal:{color:'red'}}};
                        //return val-tt;
                    }
                })
            }()
        });
    }

    function setCompareXaxis(option_day,copy,index_time,index_show,length){
        copy.xAxis=[];
        copy.xAxis.push(zrUtil.clone(option_day.xAxis[0]));
        copy.xAxis.push(zrUtil.clone(option_day.xAxis[0]));
        copy.xAxis[0].data=option_day.xAxis[0].data.slice(index_show,index_show+length);
        copy.xAxis[1].data=option_day.xAxis[0].data.slice(index_time,index_time+length);
    }

    function getIndexByName(data,name) {
        var dataLength = data.length;
        for (var i = 0; i < dataLength; i++) {
            if (data[i] == name || typeof data[i].value != 'undefined' && data[i].value == name) {
                return i;
            }
        }
        return -1;
    }

    function formatTime(time){
        return time;
    }

    function getShowDays(){
        return xAxis_show;
    }

    function getAllDays(){
        return option_2.xAxis.data||option_2.xAxis[0].data;
    }

   

    var EC={
        show:show,
        resize:function(){myChart1.resize();myChart2.resize();},
        hideDataZoom:hideDataZoom,
        removeCompare:removeCompare,
        getShowDays:getShowDays,
        getAllDays:getAllDays,
        addCompare_1:addCompare_1,
        addCompare_2:addCompare_2
    };

    //绑定刷新按钮点击事件
    $("#infoBtn").click(function(){
        var type = 2;
        if($('#time_checkbox_info').is(":checked"))
            type=0;  
        EC.show(type);
    });

    
    $(":button.btn_info[statType]").click(function(){
        changeDateGrp(this);
        $('#time_checkbox_info').attr('checked',false);
        $('#time_input_info').val('');
        $('#time_input_info').attr('disabled','');
        if($(this).attr('statType')=='week'){
            $('#time_input_info').parent().css('visibility',"hidden");
        }else{
            $('#time_input_info').parent().css('visibility',"visible");
        }
        
        EC.show(1);
    });

    //时间勾选框事件
    $('#time_checkbox_info').change(function(e){
        var input=$('#time_input_info');
        if(!input)return;
        if($(this).is(":checked")){
            input.removeAttr('disabled');
            input.attr('placeholder','选择比较时间起点');               
            EC.hideDataZoom();
            setDatePicker(EC, $('#infoOption').attr('statType'),input);
        }else{
            input.val('');
            input.attr('disabled','');
            input.attr('placeholder','添加对比');               
            EC.removeCompare();
        }
    });

    //时间选择事件
    $('#time_input_info').datepicker().on('changeDate',function(e){
        EC.addCompare_1(e.format());
        EC.addCompare_2(e.format());
    });

    return EC;
});









